package cn.zyq.demo.service.sys.impl;


import cn.zyq.demo.beans.sys.SysAdmin;
import cn.zyq.demo.beans.sys.SysJobLog;
import cn.zyq.demo.mapper.sys.SysJobLogMapper;
import cn.zyq.demo.service.sys.SysJobLogService;
import cn.zyq.demo.system.common.BaseService;
import cn.zyq.demo.system.common.PageParam;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 定时任务调度日志表
 * 2023-05-12 20:14:08
 */

@Slf4j
@Service
public class SysJobLogServiceImpl extends BaseService implements SysJobLogService {
    @Autowired
    private SysJobLogMapper sysJobLogMapper;


    @Override
    public PageInfo<SysJobLog> list(PageParam pageParam) {
        PageHelper.startPage(pageParam.getPage(), pageParam.getPageSize());
        List<SysJobLog> dbList = this.sysJobLogMapper.list(pageParam.getKv());
        return new PageInfo<>(dbList);
    }

    @Override
    public void add(SysJobLog param, SysAdmin admin) {
        // this.setCreateBaseData(param, admin);
        this.sysJobLogMapper.insertSelective(param);
    }

    @Override
    public void update(SysJobLog param, SysAdmin admin) {
        Integer id = param.getSysJobLogID();
        // this.setUpdateBaseData(param, admin);
        this.sysJobLogMapper.updateByPrimaryKeySelective(param);
    }

    @Override
    public void del(String serviceID, SysAdmin admin) {
        SysJobLog dbInfo = this.detail(serviceID);
        Integer id = dbInfo.getSysJobLogID();
        this.deleteLogic(id, admin, this.sysJobLogMapper);
    }

    @Override
    public SysJobLog detail(String serviceID, SysAdmin admin) {
        return this.detail(serviceID);
    }

    @Override
    public SysJobLog detail(String serviceID) {
        SysJobLog dbInfo = this.getByServiceID(serviceID, SysJobLog.class, this.sysJobLogMapper);
        // this.checkLogicExist(dbInfo);
        return dbInfo;
    }

    @Override
    public List<SysJobLog> selectJobLogList(SysJobLog sysJobLog) {
        return this.sysJobLogMapper.selectJobLogList(sysJobLog);
    }

    /**
     * 通过调度任务日志ID查询调度信息
     *
     * @param jobLogId 调度任务日志ID
     * @return 调度任务日志对象信息
     */
    @Override
    public SysJobLog selectJobLogById(Integer jobLogId) {
        return sysJobLogMapper.selectByPrimaryKey(jobLogId);
    }

    /**
     * 新增任务日志
     *
     * @param jobLog 调度日志信息
     */
    @Override
    public void addJobLog(SysJobLog jobLog) {
        sysJobLogMapper.insertSelective(jobLog);
    }

    /**
     * 批量删除调度日志信息
     *
     * @param logIds 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteJobLogByIds(Integer[] logIds) {
        int i = 0;
        for (Integer logId : logIds) {
            int i1 = sysJobLogMapper.deleteByPrimaryKey(logId);
            i += i1;

        }
        return i;
    }

    /**
     * 删除任务日志
     *
     * @param jobId 调度日志ID
     */
    @Override
    public int deleteJobLogById(Integer jobId) {
        return sysJobLogMapper.deleteByPrimaryKey(jobId);
    }

    /**
     * 清空任务日志
     */
    @Override
    public void cleanJobLog() {
        sysJobLogMapper.cleanJobLog();
    }
}
